<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/tld/extend.tld" prefix="extend"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>乐盈培训网 - 添加老师信息</title>
		<link href="<extend:contextPath name="contextPath"/>/css/style.css" rel="stylesheet" type="text/css" />
		<script language="JavaScript" src="<extend:contextPath name="contextPath"/>/scripts/jquery.js"></script>
		<script language="JavaScript" src="<extend:contextPath name="contextPath"/>/scripts/common.js"></script>	
	</head>
	
	<body>
	
		<div style="position:absolute; height:100%; width:1045px;">
		<jsp:include page="../header.jsp"></jsp:include>
			<table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-size:12px;">
					<tr>
						<td height="25px">
							您现在的位置：<a href="<extend:contextPath name="contextPath"/>" class="normal_link">首页</a> &gt;&gt; 
							<a href="<extend:contextPath name="contextPath"/>/admin/goToAdmin.do" class="normal_link">admin</a> >> 添加教师
						</td>
					</tr>
			</table>
		<html:form action="/addTeacherProcess.do?method=addTeacherProcess" enctype="multipart/form-data"> 
			<table style="font-size:14px">
				<tr>	
					<td height="30">老师名称：</td>
					<td>						
						<div id="name">
							<html:text property="teacherTO.teacherName" onblur="validate(this.value)"/>
						</div>						
					</td>
				</tr>
				 <tr>	
					<td valign="top">老师描述：</td>
					<td><html:textarea cols="50" rows="20" property="teacherTO.teacherDesc" /></td>
				</tr>
				<tr>	
					<td height="30">教学专业：</td>
					<td>
						<html:select property="teacherTO.teachMajor" onmouseover="getCourseCategory('teacherTO.teachMajor');">
							<html:option value="">--请选择--</html:option>
						</html:select>
					</td>
				</tr>
				<tr>	
					<td height="30">老师图片：</td>
					<td><html:file property="teacherImage" /></td>
				</tr>
				<tr>
					<td><html:submit property="bt1" disabled="true">提交</html:submit></td>
				</tr>																	
			</table>
			<script>		
				function validate(name)
				{	
					var parent = $("#name")[0]; 
					var oldImage = $("#oldImage")[0];
					if(oldImage != null)
					{
						parent.removeChild(oldImage);	
					}
					var tip = $("#tip")[0];
					if(tip != null)
					{
						parent.removeChild(tip);
					}
				
					if(name == '')	{
						var tooltip = document.createElement("label");
						tooltip.id = "tip";
						tooltip.innerHTML = "名称不能为空";
						tooltip.style.color = "red";		
						parent.appendChild(tooltip);
						document.getElementsByName("bt1")[0].disabled = true;
						return;
					}					
					
					$.ajax({
						type: "post",
						url: "<extend:contextPath name="contextPath"/>/admin/validateTeacherName.do?method=validateTeacherName",
						data:{"teacherName":name},
						beforeSend: function(XMLHttpRequest){
						},
						success: function(data, textStatus) {		
								
							if (data == "true") {
								var image = new Image();
								image.src = "<extend:contextPath name="contextPath"/>/images/dagou.bmp";
								image.id = "oldImage";																				
								parent.appendChild(image);		
								
								document.getElementsByName("bt1")[0].disabled = false;																		
							} else {
							
								var tooltip = document.createElement("label");
								tooltip.id = "tip";
								tooltip.innerHTML = "该名称已存在";
								tooltip.style.color = "red";		
								parent.appendChild(tooltip);
								document.getElementsByName("bt1")[0].disabled = true;
							}														
						},
						complete: function(XMLHttpRequest, textStatus){
							//HideLoading();
						},
						error: function(){
							alert("failure");
						}							
					});
				}
			</script>
		</html:form>
	</div>	
	</body>
</html>